{template 'header','member'}
<div class="main-block bd-gray mt10">
	<div class="hd fn-clear">
		<h2 class="fn-left">车主金卡认证</h2>
	</div>
	<ul id="data-nav" class="main-nav mt10 fn-clear">
		<li  class='current'><a>车主金卡认证</a></li>
	</ul>
{if !$status}
	<form id="pub-form" name="pub-form" method="post" action="{url('member/checkcard')}">
		<input type="hidden" name="post[checknum]" value="{$checknum}" id='checknum'/>
	<table class="data-form c666 mt10">
		<tr>
			<th width="90">输入编号：</th>
			<td><input type="text" size="25" id='cardnum' name='post[cardnum]' {if $checknum<=0}disabled='disabled'{/if}></td>
		</tr>
		<tr>
			<th width="90">输入密码：</th>
			<td><input type="text" size="10"  id='cardcode' name='post[cardcode]' {if $checknum<=0}disabled='disabled'{/if}></td>
		</tr>
		<tr>
			<th width="90"></th>
			<td>您今天还剩<span style="color: #f00" id='cnum'>{$checknum}</span>次认证机会(每天有3次认证机会)</td>
		</tr>
		<tr>
			<th>&nbsp;</th>
			<td class="sub-info">
				<button type="submit" class="btn" id='card-sub'>点击认证</button>
			</td>
		</tr>
	</table>
        <script type="text/javascript">
            seajs.use(['$'],function($){
                $("#cardnum").keydown(function(e){
                    var num = $(this).val(),
                            realNum = num.replace(/\s/g, ''),
                            newNum;
                    if(!(e.keyCode == 8 || e.keyCode == 46) && realNum.length>0 && realNum.length%4 == 0 ){
                        newNum = num+" ";
                        $(this).val(newNum);
                    }
                });
            });
        </script>
	</form>
{else}
	<table class="data-form c666 mt10">
		<tr>
			<th width="90">编号：</th>
			<td>{$cardnum}</td>
		</tr>
		<tr>
			<th width="90">持卡会员：</th>
			<td>{$username}</td>
		</tr>
		<tr>
			<th width="90">认证时间：</th>
			<td>{timetodate($addtime,3)}</td>
		</tr>
		<tr>
			<th width="90">失效时间：</th>
			<td>{timetodate($expiretime,3)}</td>
		</tr>
		<tr>
			<th width="90">状态：</th>
			<td>{if OwnCardModule::checkExpire($username)}使用中{else}已过期{/if}</td>
		</tr>
	</table>
{/if}
</div>
<script type="text/javascript">
	seajs.use(['$','easyui', 'easyui-css'], function ($) {
			$('#pub-form').form({
				url:lemon.site_url+'ajax.php',
				onSubmit: function(param){
					param.action        = 'checkcard';
					param.checknum      = $('#checknum').val();
					param.cardnum       = $('#cardnum').val();
					param.cardcode      = $('#cardcode').val();
					param.username      = "{$username}";
					if(param.checknum == '0'){
						alert('很抱歉,您今天的认证机会已耗尽，明天再来吧！');
						return false;
					}
					if (!param.cardnum) {
						$("#cardnum").validatebox({
							required:true,
							validType:['length[1,20]'],
							missingMessage:'请输入编号'
						});
						return false;
					}
					if (!param.cardcode) {
						$("#cardcode").validatebox({
							required:true,
							validType:['length[1,20]'],
							missingMessage:'请输入密码'
						});
						return false;
					}

				},
				success:function(data){
					var str = $.parseJSON(data);
					$('#cnum').text(str.checknum);
					$('#checknum').val(str.checknum);
					alert(str.msg);
					if(str.success == 'true'){
						window.location.href="{url('member/my')}?mid=37";
					}
					return false;
				}
			})


	})
</script>
{template 'footer', 'member'}